#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> acts;
    while (n--) {
        int num1, num2;
        cin >> num1 >> num2;
        acts.push_back({num1, num2});
    }
    sort(acts.begin(), acts.end(), [](const vector<int>& a, const vector<int>& b) {
        return a[1] < b[1];
    });
    int ans = 0;
    int last_end=-1;

    for (int i = 0; i < acts.size(); i++) {
       int st=acts[i][0];
       int ed=acts[i][1];
       if(st>=last_end){
        ans++;
        last_end=ed;
       }
    }
    cout << ans << endl;
}
